package com.cloudkinto.controller.dic;


import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.exception.BizException;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.dic.vo.dicBusiness.DicBusinessAddReq;
import com.cloudkinto.service.dic.vo.dicBusiness.DicBusinessUpdateReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cloudkinto.service.dic.DicBusinessService;

import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;

import java.util.HashMap;
import java.util.Map;

import com.cloudkinto.base.BaseController;

/**
 * <p>
 * 业务码表主表 前端控制器
 * </p>
 * @author 张永远
 * @since 2020-05-19
 */
@RestController
@Api(tags = "业务码表主表模块")
@RequestMapping("/api/dicBusiness")
public class DicBusinessController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(DicBusinessController.class);

    @Autowired
    private DicBusinessService service;

    @UserSessionRequired
    @PostMapping("")
    @ApiOperation(value = "业务码表主表新增", notes = "业务码表主表新增")
    public SingleResult add(@RequestBody @Validated DicBusinessAddReq req) throws BizException {
        Long userId = getCurrentUserId();
        return SingleResult.success("新增成功",service.add(req,userId));
    }

    @UserSessionRequired
    @PutMapping("")
    @ApiOperation(value = "业务码表主表修改", notes = "业务码表主表修改")
    public SingleResult update(@RequestBody @Validated DicBusinessUpdateReq req) throws BizException {
        Long userId = getCurrentUserId();
        return SingleResult.success("修改成功",service.update(req,userId));
    }

    @UserSessionRequired
    @DeleteMapping("/{id}")
    @ApiOperation(value = "业务码表主表根据id删除", notes = "业务码表主表根据id删除")
    public SingleResult delete(@PathVariable("id") Long id) {
        Long userId = getCurrentUserId();
        return SingleResult.success("删除成功",service.delete(id,userId));
    }

//    @GetMapping("/{id}")
//    @ApiOperation(value = "业务码表主表根据id查看详情", notes = "业务码表主表根据id查看详情")
//    public SingleResult detail(@PathVariable("id") Long id) {
//        return SingleResult.success("查询成功",service.detail(id));
//    }
//
//    @GetMapping("/list")
//    @ApiOperation(value = "业务码表主表查询", notes = "业务码表主表查询")
//    public SingleResult list(HttpServletRequest request){
//        Map<String, String> map = new HashMap<>();
//        String keyword = request.getParameter("keyword");
//        map.put("keyword", keyword);
//        return SingleResult.success("查询成功", service.getList(map));
//    }
//
//    @GetMapping("/listPage")
//    @ApiOperation(value = "业务码表主表查询（分页）", notes = "业务码表主表查询（分页）")
//    public PageResult listPage(HttpServletRequest request){
//        Map<String, String> map = new HashMap<>();
//        String keyword = request.getParameter("keyword");
//        String current = request.getParameter("current");
//        String size = request.getParameter("pageSize");
//        map.put("keyword", keyword);
//        map.put("current", current);
//        map.put("pageSize", size);
//        return service.getListPage(map);
//    }

}

